|
How Do I Set Up and Enable the A7’s Memory Protection Unit (MPU) and Cache? The A7’s memory protection unit (MPU), shown in Figure 1, supports up to eight separate memory regions, each with individual sizes, privileges, and cache settings. Figure 1. The A7’s Memory Protection Unit (MPU). The A7 Hardware Abstraction Layer (A7HAL), which is part of the Triscend Software Development Kit (SDK), includes convenient routines for initializing and enabling the A7’s MPU and cache.
To use the A7HAL, be sure to include it as part of your main program. #include <a7hal.h>
First, declare a structure that defines the MPU settings. The A7HAL has a pre-defined structure called a7hal_mpu_map. In the structure, declare the following attributes for each of the eight protected regions. Region 7 has the highest priority and Region 0 the lowest.
a7hal_mpu_map myMap[] = {
/* From Region 7 down to Region 0 */ /* Enable access to first 32MB of
address space */ {0xc0000000, A7HAL_SIZE_4MB, A7HAL_SUP_RW_USR_RW, YES},
/* Enable
access to first 2MB of FLASH */
/* Enable
access to 64KB for A7’s control registers */
/* Enable access to the 16KB for A7’s
internal SRAM */
/* Enable access to 1MB region for memory-mapped CSL registers. These registers cannot be cached */ {0x10000000, A7HAL_SIZE_1MB, A7HAL_SUP_RW_USR_RW, NO},
/* Empty region */ {0x00000000, 0, 0, NO},
/* Empty region */ {0x00000000, 0, 0, NO},
After setting up the MPU, create a routine to handle any memory aborts. A memory abort occurs when the A7 attempts a transaction to a region in memory not defined by one of the MPU’s memory areas, as shown in Figure 1. If such a transaction occurs, decide how you wish to handle this condition. In this simple example, the memory abort handler reports the error and continues with the next instruction. The next instruction executed depends on whether the handler is compiled in ARM or Thumb mode. /* * Abort Interrupt Handler */ void abortHandler( unsigned long Addr ) { printf("Abort exception at address 0x%08x\n", Addr); #ifdef __THUMB__ printf("Program continues at address 0x%08x\n", Addr + 2); #else printf("Program continues at address 0x%08x\n", Addr + 4); #endif }
Finally, in your main program, initialize the memory abort handler and then program and enable the MPU. /* * MAIN FUNCTION */ int main( ) { /* Initialize the memory abort handle created above */ a7hal_icu_setUserAbort( abortHandler );
/* Program the settings into the MPU */ a7hal_mpu_setMap( myMap ); /* Enable the map */ a7hal_mpu_enableMap( );
printf( "So far so good...\n" );
/* Create a pointer that points to an unspecified area in memory */ int *Pointer = ( int * ) 0x20000000;
/* This next line causes an abort exception because the transaction is to a memory location not specified in the MPU settings */ *Pointer = 0x55aa55aa;
printf( "Done\n" );
/* Never return from main */ while (1) ;
} /* end main.c */
Base AddressFigure 2 shows the A7’s memory map after initialization. The addresses along the left show the base address for various features in the memory map. The numbers to the right of each region show its size.
Figure 2. The A7’s Memory Map after Initialization. Area SizeThe size for each protected area can range from 4KB up to 4GB. The A7HAL provides enumerated values to specify the area size, as shown in Table 1. Table 1. Enumerated Values for Area Size.
PermissionsEach protected area can grant separate read and write privileges to the supervisor and user modes. The A7HAL provides enumerated values to specify the permissions, as shown in Table 2. Table 2. Enumerated Values for Area Permissions.
© 2002 by Triscend Corporation. All rights reserved. |